package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("userOrderController")
@ApiOperation("C端-订单相关接口")
@Slf4j
@RequestMapping("/user/order")
public class OrderController {
    @Resource
    private OrderService orderService;

    /*
    * 用户下单
    * */
    @ApiOperation("用户下单")
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        log.info("用户下单:{}",ordersSubmitDTO);
        OrderSubmitVO submit = orderService.submit(ordersSubmitDTO);
        return Result.success(submit);
    }

    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<Orders> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        Orders orders = orderService.paySuccess(ordersPaymentDTO.getOrderNumber());
        return Result.success(orders);
    }

    /*
    * 历史订单
    * */
    @ApiOperation("历史订单")
    @GetMapping("/historyOrders")
    public Result<PageResult> listHistory(int page, int pageSize, Integer status){
        log.info("查询历史订单:页码:{},记录数:{},状态:{}",page,pageSize,status);
        PageResult pageResult = orderService.listHistory(page,pageSize,status);
        return Result.success(pageResult);
    }

    /*
    * 再来一单
    * */
    @ApiOperation("再来一单")
    @PostMapping("/repetition/{id}")
    public Result repetition(@PathVariable Long id){
        log.info("再来一单:{}",id);
        orderService.repetition(id);
        return Result.success();
    }

    /*
    * 订单查看
    * */
    @ApiOperation("订单查看")
    @GetMapping("/orderDetail/{id}")
    public Result view(@PathVariable Long  id){
        log.info("查看订单:{}",id);
        OrderVO view = orderService.view(id);
        return Result.success(view);
    }

    /*
    * 取消订单
    * */
    @ApiOperation("取消订单")
    @PutMapping("/cancel/{id}")
    public Result cancel(@PathVariable Long id){
        log.info("取消订单:{}",id);
        orderService.userCancel(id);
        return Result.success();
    }

    /*
    * 用户催单
    * */
    @ApiOperation("用户催单")
    @GetMapping("/reminder/{id}")
    public Result reminder(@PathVariable Long id){
        orderService.reminder(id);
        return Result.success();
    }
}
